package com.shiyu.springssmemployeegit.controller;


import com.shiyu.springssmemployeegit.pojo.Employee;
import com.shiyu.springssmemployeegit.service.EmployeeService;
import com.shiyu.springssmemployeegit.utils.PageDto;
import com.shiyu.springssmemployeegit.utils.PageVo;
import com.shiyu.springssmemployeegit.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "员工管理")
@ResponseBody
@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    //通过id查询员工并且返回json
    @Operation(summary = "通过id查询员工")
    @GetMapping("/get/{id}")
    public Employee getEmployeeById(@PathVariable("id") Long id) {
        return employeeService.findEmployeeById(id);
    }

    //插入员工
    @Operation(summary = "插入员工")
    @PostMapping("/insert")
    public String insertEmployee(@RequestBody Employee employee) {
        return employeeService.insertEmployee(employee) ? "插入成功" : "插入失败";
    }

    //修改员工信息
    @Operation(summary = "修改员工信息")
    @PutMapping("/update")
    public String updateEmployee(@RequestBody Employee employee) {
        return employeeService.updateEmployee(employee) ? "修改成功" : "修改失败";
    }

    //删除员工
    @Operation(summary = "删除员工")
    @DeleteMapping("/delete/{id}")
    public String deleteEmployee(@PathVariable("id") Long id) {
        return employeeService.deleteEmployee(id) ? "删除成功" : "删除失败";
    }
    @Operation(summary = "分页查询")
    @GetMapping("/pageList")
    public Result pageList(PageDto pageDto){
        PageVo result= employeeService.pageList(pageDto);
        return Result.success(result);
    }
}
